<?php
    //----------------------------------------------------------------------------------
    //ACTION FUNCTIONS
    //Write in this file all actions you need to perform.
    //This is the only file you need to edit to add functionality to the backend.
    //For the frontend part edit "js/functions.js".
    //Convention: try to declare frontend and backend functions with the same name.
    //----------------------------------------------------------------------------------
    function test($data){
        $testArray = array ("functionName" 	=> "test",
                            "description"	=> "Everything allright?");

        $response = getResponse("ok", "function: test", $testArray);
        return $response;
    }
    //----------------------------------------------------------------------------------
    function getPhrasePart($json){
        $dataObj = json_decode(stripslashes($json));

        //eval obj completeness
        if(empty($dataObj->field)) return getResponse("err", "noField");
        if(empty($dataObj->value)) return getResponse("err", "noValue");

        //return phrase part for field value pair
        $field = ucfirst(strtolower($dataObj->field));
        return call_user_func("getPhrasePartFor$field", $dataObj->value);
    }
    //----------------------------------------------------------------------------------
    function getPhrasePartForName($value){
        //TODO: analize whole name
        $nameArray = explode(" ", $value);
        $value = $nameArray[0];

        $value              = strtolower($value);
        $defaultPhrase      = 'Ví';
        include('includes/mappings/nameMappings.php');
       
        if(array_key_exists($value, $map)) return getResponse('ok', 'responseFromGetPhrasePartForName', $map[$value]);
        return getResponse('ok', 'responseFromGetPhrasePartForName', $defaultPhrase);
    }
    //----------------------------------------------------------------------------------
    function getPhrasePartForDay($value){
        if(is_nan($value)) return getResponse('err', 'dayValueShouldBeANumber');
        $defaultPhrase      = 'objetos';
        include('includes/mappings/dayMappings.php');

        if(array_key_exists($value, $map)) return getResponse('ok', 'responseFromGetPhrasePartForDay', $map[$value]);
        return getResponse('ok', 'responseFromGetPhrasePartForDay', $defaultPhrase);
    }
    //----------------------------------------------------------------------------------
    function getPhrasePartForMonth($value){
        if(is_nan($value)) return getResponse('err', 'monthValueShouldBeANumber');
        $defaultPhrase      = 'en';
        include('includes/mappings/monthMappings.php');

        if(array_key_exists($value, $map)) return getResponse('ok', 'responseFromGetPhrasePartForMonth', $map[$value]);
        return getResponse('ok', 'responseFromGetPhrasePartForMonth', $defaultPhrase);
    }
    //----------------------------------------------------------------------------------
    function getPhrasePartForYear($value){
        if(is_nan($value)) return getResponse('err', 'yearValueShouldBeANumber');
        $defaultPhrase      = 'en un lugar insólito';
        include('includes/mappings/yearMappings.php');

        if(array_key_exists($value, $map)) return getResponse('ok', 'responseFromGetPhrasePartForYear', $map[$value]);
        return getResponse('ok', 'responseFromGetPhrasePartForYear', $defaultPhrase);
    }
    //----------------------------------------------------------------------------------
    function getPhrasePartForEspecialidad($value){
        $defaultPhrase      = 'apretando';
        include('includes/mappings/professionMappings.php');

        if(array_key_exists($value, $map)) return getResponse('ok', 'responseFromGetPhrasePartForEspecialidad', $map[$value]);
        return getResponse('ok', 'responseFromGetPhrasePartForEspecialidad', $defaultPhrase);
    }
    //----------------------------------------------------------------------------------
    function getPhrasePartForDeporte($value){
        $defaultPhrase      = 'mi porra';
        include('includes/mappings/sportMappings.php');

        if(array_key_exists($value, $map)) return getResponse('ok', 'responseFromGetPhrasePartForDeporte', $map[$value]);
        return getResponse('ok', 'responseFromGetPhrasePartForDeporte', $defaultPhrase);
    }
    //----------------------------------------------------------------------------------
    function getPhrasePartForMusica($value){
        $defaultPhrase      = 'en';
        include('includes/mappings/musicgenreMappings.php');

        if(array_key_exists($value, $map)) return getResponse('ok', 'responseFromGetPhrasePartForMusica', $map[$value]);
        return getResponse('ok', 'responseFromGetPhrasePartForMusica', $defaultPhrase);
    }
    //----------------------------------------------------------------------------------
    function getPhrasePartForColor($value){
        $defaultPhrase      = 'tus ganas!';
        include('includes/mappings/colorMappings.php');

        if(array_key_exists($value, $map)) return getResponse('ok', 'responseFromGetPhrasePartForColor', $map[$value]);
        return getResponse('ok', 'responseFromGetPhrasePartForColor', $defaultPhrase);
    }
    //----------------------------------------------------------------------------------
?>